var mysql =require('mysql')
function db(sql,params,cb){
    var connection =mysql.createConnection({
        host:"localhost",
        port:3306,
        database:'testdb',
        user:'root',
        password:'123456',
        multipleStatements:true
    });
    connection.connect(function(err){
        if(err){
            console.log('数据库连接失败')
            res.end(JSON.stringify({code:500,message:'无法查询数据'}))
        }
        else{
            connection.query(sql,params,function(err,results){
                if(err){
                    cb(err,null)
                }
                else{
                    cb(null,results)
                }
            })
        }
        connection.end();
    });
    
}
module.exports = db